package com.servlet;

import com.dao.*;
import com.entity.user;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class fukuan extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        searchdao s =new searchdaoimpl();
        String name=s.searchcookie(req);
        String sj= (String) req.getSession().getAttribute("shijian");
        String s2= (String) req.getSession().getAttribute("user");
        String s3= (String) req.getSession().getAttribute("pid");
        String s4=req.getParameter("tprice");
        String s5=req.getParameter("time");
        randomid r=new randomid();
        String s6=r.randomid();
        String s7=r.randomid();
        String s8=s5;
        if("two".equals(s.searchsjcookie(req))){
            s8= String.valueOf(Integer.parseInt(s5)*24);
        }else if("three".equals(s.searchsjcookie(req))){
            s8=String.valueOf(Integer.parseInt(s5)*24*7);
        }
        String money="";
        String sql="select * from user where UserID=?";
        UserInfDao u=new UserInfDao();
        List<user> list =u.getForList(user.class,sql,name);
        for (int i = 0; i < list.size(); i++) {
            money=money.concat(list.get(0).getMoney());
        }
            String sql1 = "insert into myorder values(?,?,?,?,?)";
            String sql2 = "insert into orderdetails values(?,?,?,?)";
            u.update(sql2, s7, s4, s8, s3);
            u.update(sql1, s6, name, s2, s3, s7);
            rechangedao r1 = new rechangedaoimpl();
            r1.pay(s4, name, s2);
            Cookie cookie=new Cookie("zfcg","yes");
            resp.addCookie(cookie);
            resp.sendRedirect("zuhaodating.jsp");
    }
}
